<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim" id="website-sms" lay-title="短信管理"
     xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="topic-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">邮箱号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="receiveMobile" autocomplete="off"
                                                   class="layui-input"
                                                   placeholder="请输入邮箱号">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">发送时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="time" id="sendTime" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="smsTable" lay-data="{id: 'smsTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'website', 'dict', 'laydate'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            $view = $('#website-sms'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            sendTimeFrom,
            sendTimeTo
        ;
        form.render();
        initTable();
        laydate.render({
            elem: '#sendTime',
            range: true,
            trigger: 'click',
            trigger: 'click'
        });

        /**
         * 表格的排序点击
         **/
        table.on('sort(smsTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            sendTimeFrom = null;
            sendTimeTo = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });


        /**
         * 初始化表格
         */
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'smsTable',
                url: ctx + 'sysSms/list',
                cols: [[
                    {type: 'numbers', title: '序号',},
                    {field: 'sendTime', title: '发送时间', minWidth: 100},
                    {field: 'receiveMobile', title: '邮箱', minWidth: 100},
                    {field: 'contentJson', title: '发送内容', minWidth: 100},
                ]]
            });
        }

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            var sendTime = params.time;
            if (sendTime) {
                sendTimeFrom = sendTime.split(' - ')[0];
                sendTimeTo = sendTime.split(' - ')[1];
            }
            params.sendTimeFrom = sendTimeFrom;
            params.sendTimeTo = sendTimeTo;
            return params;
        }

    })
</script>